var $buyPop = $('.buy-pop');
var $times = $('#times');

var S = new iSlider(document.getElementById('sliderWrap'), $('#sliderWrap img').map(function(){
    var src = this.src;
    this.parentNode.removeChild(this);
    return {content: src};
}), {
    isLooping: 1,
    plugins: ['dot']
});

var popup = function(){

    var $pop = $('<div class="pop-mask"><div class="popup"><div class="inner"></div><div class="button">确定</div></div></div>').appendTo('body');
    return {
        show: function(content){
            $pop.show(0, function(){
                $pop.find('.inner').html(content);
                $pop.find('.popup').addClass('popup-in');
            });
        },
        hide: function(){
            $pop.hide();
            $pop.find('.inner').empty();
            $pop.find('.popup').removeClass('popup-in');
        },
        $el: $pop
    }
}();

$('#buyBtn').on('click',function(){
    $buyPop.show(0,function(){
        $buyPop.find('.box').addClass('toup');
    });
    return false;
});

$buyPop.on('touchmove',function(){
    return false;
}).on('click',function(e){
    if(e.target.className == 'buy-pop'){
        this.removeAttribute('style');
        $buyPop.find('.box').removeClass('toup');
    }
});

$('#clsPop').on('click',function(){
    $buyPop.removeAttr('style');
    $buyPop.find('.box').removeClass('toup');
});

$('.times ._change').on('touchend',function(){
    var val = $times.val();
    if(this.className.indexOf('plus')  == 0){
        $times.val(++val);
    }else{
        $times.val(val > 1 ? --val : 1);
    }
});

$times.on('blur',function(){
    this.value = +this.value.replace(/\D/g,'') || 1;
});

// popup绑定关闭事件
popup.$el.find('.button').on('touchend',popup.hide);


// 显示弹窗DEMO
$('#showPop').on('touchend',function(){
    // popup.show('本期您已参与'); //text
    popup.show('本期您已参与<br>感谢您参与一元夺宝'); // html 多行
    return false;
});
